package cc.wanforme.st.server;

import java.util.Collections;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

public class CodeGenerator {

	public static void main(String[] args) {
		String url = "jdbc:mysql://localhost:3306/landtest?useUnicode=true&characterEncoding=UTF-8&atuoReconnect=true&serverTimezone=GMT%2B8";
		String username ="root";
		String password ="ops#6547@M";
		String author = "wanne";
		
//		String[] tables = { "sim_story", "sim_chaptor", "sim_case", "sim_option"};
		String[] tables = { "user_role" };
		
		String projectPath = System.getProperty("user.dir");
		
		FastAutoGenerator.create(url, username, password)
	    .globalConfig(builder -> {
	        builder.author(author) // 设置作者
	            .enableSwagger() // 开启 swagger 模式
	            .fileOverride() // 覆盖已生成文件
	            .outputDir(projectPath + "\\src\\main\\java"); // 指定输出目录
	    })
	    .packageConfig(builder -> {
	        builder.parent("cc.wanforme.st.server") // 设置父包名
	            .moduleName("base") // 设置父包模块名
	            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, projectPath + "\\src\\main\\resources\\mapper\\base")); // 设置mapperXml生成路径
	    })
	    .strategyConfig(builder -> {
	        builder.addInclude(tables); // 设置需要生成的表名
//	            .addTablePrefix("t_", "c_"); // 设置过滤表前缀
	    })
	    .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
	    .execute();
	}
	
}
